package org.practice.action;

import javax.servlet.http.HttpServletResponse;

import org.practice.model.User;
import org.practice.service.UserService;
import org.practice.util.ShopServiceFactory;

@SuppressWarnings("serial")
public class RegisterCheckEmailAction extends BaseAction {
	private User user;
	@Override
	public String execute() throws Exception {
//		Client Browser的Ajax异步访问Server RegisterCheckEmailAction目的是验证该email是否被使用了
		boolean flag = false;
		if (user.getEmail() != null) {
			UserService userService = ShopServiceFactory.createUserService();
			flag = userService.checkEmail(user.getEmail());
		}
		System.out.println("flag=="+flag);
		HttpServletResponse response=getResponse();
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		response.setDateHeader("Expires", 0);
		response.setContentType("text/html;charset=utf-8");
		response.getWriter().print("{'value':" + flag + "}");
		response.getWriter().flush();
		response.getWriter().close();
		
		return null;
	}
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	
}
